home *** CD-ROM | disk | FTP | other *** search
- Path: pluto.njcc.com!not-for-mail
- From: mike@pluto.njcc.com (Michael Hohenshilt)
- Newsgroups: comp.lang.c++
- Subject: Re: Calling the wrong constructor
- Date: 15 Apr 1996 15:08:31 GMT
- Organization: New Jersey Computer Connection, Lawrenceville, NJ
- Message-ID: <4ktopf$21s@earth.njcc.com>
- References: <4kot87$796@earth.njcc.com> <4kpm4c$jfe@nntp1.best.com> <3170DEB7.66C6@sto.fdata.se>
- NNTP-Posting-Host: pluto.njcc.com
- X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
-
- Niklas Mellin (niklas.mellin@sto.fdata.se) wrote:
- : > The destructors need to be virtual.
- : >
- : > virtual ~Foo() { { /* ... */ }
- : > virtual ~Parent() { /* ... */ }
- :
- : Only Parent has to be expicitly declared virtual, declaring derived
- : classes overloaded functions as virtual when they are already declared
- : virtual in the base class is optional. A good habit though since it
- : might make the code clearer.
- : ---
- : Niklas Mellin
-
- Thanks for that tip. I didn't think you could declare a destructor as
- virtual (Okay to be honest, it never occured to me either). I did solve
- the problem however. Messy, messy, messy technique by adding a new
- virtual function that allows the derived class to destroy itself from the
- base class' destructor (this emulated a destructor). The worst part about
- it is that I have about 10 derived classes (and still growing) where
- most of them required a custom Destroy function (there own destructors
- became pretty much obsolete afterwards), but I'm going to change it. In
- fact I put my little project aside (well...it's not so little anymore),
- and play around with the language some more by pushing the C++ language
- to it's limits and hopefully get some more insight into the language.
-
- Thanks again
-
- : Michael Hohenshilt
- : Wisdom is ofttimes nearer when we stoop
- : Than when we soar.
-
-